/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JanusValuesJPanel.java
 *
 * Created on Oct 1, 2011, 4:16:06 PM
 */

package org.opmviewer.jframes;

import java.io.File;
import javax.swing.JFileChooser;
import org.opmviewer.valueproviders.JanusValueProvider;
import org.opmviewer.valueproviders.ValueProvider;

/**
 *
 * @author grzegorz
 */
public class JanusValuesJPanel extends javax.swing.JPanel implements
ValuesPanel {

    /** Creates new form JanusValuesJPanel */
    public JanusValuesJPanel() {
        initComponents();
        setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        janusFileField = new javax.swing.JTextField();
        browseButton2 = new javax.swing.JButton();

        jLabel1.setText("Janus file to use:");

        browseButton2.setText("Browse ...");
        browseButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(browseButton2)
                            .addComponent(janusFileField, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(37, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(janusFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(browseButton2)
                .addContainerGap(172, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void browseButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButton2ActionPerformed
        JFileChooser jfc = new JFileChooser();
        jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {

            @Override
            public boolean accept(File f) {
                return f.getName().endsWith(".rdf") || f.isDirectory();
            }

            @Override
            public String getDescription() {
                return "*.rdf";
            }
        });
        jfc.setDialogTitle("Choose OPM file location");
        jfc.setMultiSelectionEnabled(false);
        jfc.showDialog(this, "Choose");
        File f = jfc.getSelectedFile();
        if (f != null) {
            janusFileField.setText(f.getAbsolutePath());
        }
}//GEN-LAST:event_browseButton2ActionPerformed

    public void setActive(boolean active){
            browseButton2.setEnabled(active);
            janusFileField.setEnabled(active);
    }
    public ValueProvider getValueProvider(){
        return new JanusValueProvider(janusFileField.getText());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton browseButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField janusFileField;
    // End of variables declaration//GEN-END:variables

}
